package com.webside.wap.search.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.webside.base.baseservice.impl.AbstractService;
import com.webside.wap.common.mapper.BSeriesMapper;
import com.webside.wap.common.mapper.BdictionaryMapper;
import com.webside.wap.common.model.BSeries;
import com.webside.wap.common.model.Bdictionary;
import com.webside.wap.search.service.SearchService;
import com.webside.loginfo.model.LogInfoEntity;
import com.webside.util.PageUtil;

@Service("searchService")
public class SearchServiceImpl extends AbstractService<LogInfoEntity, Long> implements SearchService{
	
	@Autowired
	private BdictionaryMapper bdictionaryMapper;
	
	@Autowired
	private BSeriesMapper bSeriesMapper;
	 
	/**
	 * 通过查询code返回Bdictionary获取type等需要的属性 
	 * @param code
	 * @return
	 */
	public List<Bdictionary> queryByCode(String code) {
		return bdictionaryMapper.queryByCode(code);
	}

	/**
	 * 通过传递的 Bdictionary对象的code type进行查询
	 * 通过传入的sort字段进行升序排序（从小到大）
	 * @param bdictionary
	 * @return
	 */
	public List<Bdictionary> queryByCodeAndTypeAsc(Bdictionary bdictionary,String sort) {
		return bdictionaryMapper.queryByTypeAndCodeAsc(bdictionary,sort);
	}
	/**
	 * 通过传递的 Bdictionary对象的code type进行查询
	 * 通过传入的sort字段进行降序排序（从小到大）
	 * @param bdictionary
	 * @return
	 */
	public List<Bdictionary> queryByCodeAndTypeDesc(Bdictionary bdictionary,String sort) {
		return bdictionaryMapper.queryByTypeAndCodeDesc(bdictionary,sort);
	}

	/**
	 * 根据条件查询电影（带分页）
	 * @param bSeries
	 * @param pageUtil
	 * @param sort
	 * @return
	 */
	public List<BSeries> findBSeriesByPageVo(BSeries bSeries, PageUtil pageUtil, String sort) {
		// TODO Auto-generated method stub
		int beginSize=0;
		if (pageUtil!=null) {
			pageUtil.setPageSize(8);
			beginSize = (pageUtil.getPageNum()-1)*pageUtil.getPageSize();
		}else {
			pageUtil=new PageUtil();
			pageUtil.setPageSize(8);
		}
		
		System.out.println("beginSize:"+beginSize);
		return bSeriesMapper.searchSeriesByPageVo(bSeries, pageUtil,beginSize, sort);
	}
	/**
	 * 根据BSeries条件构建的BSeries对象返回记录数
	 * @param record
	 * @return
	 */
	public int getProductsCount(BSeries bSeries) {
		return bSeriesMapper.getProductsCount(bSeries);
	}
	
	
}
